from datetime import datetime, timedelta

def get_dates(start_date, end_date, days):
    start_date = datetime.strptime(start_date, '%Y-%m-%d')
    end_date = datetime.strptime(end_date, '%Y-%m-%d')
    result = []

    while start_date <= end_date:
        if start_date.weekday() in days:
            result.append(start_date.strftime('%Y-%m-%d'))
        start_date += timedelta(days=1)

    return result

start_date = '2024-04-01'
end_date = '2024-04-30'
days = [1, 2, 5]
print(get_dates(start_date, end_date, days))


# import os
# import requests
# import redis
# import schedule
# import time
# from dotenv import load_dotenv
#
# # 加载 .env 文件中的环境变量
# load_dotenv()
# # 从环境变量中获取 APPID 和 APPSECRET
# APPID = os.getenv('G_APPID')
# APPSECRET = os.getenv('G_SECRET')
# # 连接到 Redis
# redis_client = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True)
#
#
# def get_access_token():
#     url = f"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={APPID}&secret={APPSECRET}"
#
#     try:
#         response = requests.get(url)
#         data = response.json()
#
#         if 'access_token' in data:
#             access_token = data['access_token']
#             expires_in = data['expires_in']
#
#             # 将 access_token 存储到 Redis，并设置过期时间为 expires_in 秒
#             redis_client.set('wechat_access_token', access_token, ex=expires_in)
#             print('Access token stored in Redis:', access_token)
#
#         else:
#             print('Error fetching access token:', data)
#
#     except Exception as e:
#         print('Exception while fetching access token:', str(e))
#
#
# # 定时任务，每两个小时获取一次 access token
# schedule.every(2).hours.do(get_access_token)
# # 立即执行一次获取 access token 的任务
# get_access_token()
#
# # 开始调度
# while True:
#     schedule.run_pending()
#     time.sleep(1)